package edu.zut.main.thread;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class ThreadDemo2 {

    public static void main(String[] args) {

        //接口模式实现多线程的创建
        ImgDownThread imgDownThread = new ImgDownThread("https://image.baidu.com/search/detail?ct=503316480&z=&tn=baiduimagedetail&ipn=d&word=%E5%9B%BE%E7%89%87&step_word=&ie=utf-8&in=&cl=2&lm=-1&st=-1&hd=undefined&latest=undefined&copyright=undefined&cs=3058617224,3417601405&os=1463992437,2628131171&simid=3413681215,255279981&pn=17&rn=1&di=211200&ln=1815&fr=&fmq=1630898856851_R&ic=0&s=undefined&se=&sme=&tab=0&width=&height=&face=undefined&is=0,0&istype=2&ist=&jit=&bdtype=0&spn=0&pi=0&gsm=0&objurl=https%3A%2F%2Fgimg2.baidu.com%2Fimage_search%2Fsrc%3Dhttp%253A%252F%252Fimg1.cache.netease.com%252Fcnews%252F2009%252F8%252F25%252F200908250951595947a.jpg%26refer%3Dhttp%253A%252F%252Fimg1.cache.netease.com%26app%3D2002%26size%3Df9999%2C10000%26q%3Da80%26n%3D0%26g%3D0n%26fmt%3Djpeg%3Fsec%3D1633490857%26t%3D7449d262d6a2739cdfa33b9f028a9a75&rpstart=0&rpnum=0&adpicid=0&nojc=undefined","1.jpg");
        Thread thread = new Thread(imgDownThread);
        thread.start();

        ImgDownThread imgDownThread2 = new ImgDownThread("https://image.baidu.com/search/detail?ct=503316480&z=&tn=baiduimagedetail&ipn=d&word=%E5%9B%BE%E7%89%87&step_word=&ie=utf-8&in=&cl=2&lm=-1&st=-1&hd=undefined&latest=undefined&copyright=undefined&cs=1082140274,3811265015&os=1890750408,4050413270&simid=3463924913,360841174&pn=23&rn=1&di=205480&ln=1815&fr=&fmq=1630898856851_R&ic=0&s=undefined&se=&sme=&tab=0&width=&height=&face=undefined&is=0,0&istype=2&ist=&jit=&bdtype=0&spn=0&pi=0&gsm=0&objurl=https%3A%2F%2Fgimg2.baidu.com%2Fimage_search%2Fsrc%3Dhttp%253A%252F%252Fimg.pconline.com.cn%252Fimages%252Fupload%252Fupc%252Ftx%252Fphotoblog%252F1404%252F26%252Fc5%252F33596317_33596317_1398517630015_mthumb.jpg%26refer%3Dhttp%253A%252F%252Fimg.pconline.com.cn%26app%3D2002%26size%3Df9999%2C10000%26q%3Da80%26n%3D0%26g%3D0n%26fmt%3Djpeg%3Fsec%3D1633490857%26t%3D12d823d3fc0fe2924016b8be5d89362d&rpstart=0&rpnum=0&adpicid=0&nojc=undefined", "2.jpg");
        new Thread(imgDownThread2).start();
    }

}

/**
 * 线程的创建：
 *  1、继承Thread，重写run方法
 *  2、实现Runnable接口，实现run方法
 *
 *  利用多线程模拟同时从网上下载多个图片
 */
class ImgDownThread implements Runnable{

    private String url;
    private String pathName;

    public ImgDownThread(String url, String pathName) {
        this.url = url;
        this.pathName = pathName;
    }

    @Override
    public void run() {
        new ImgDown().down(url,pathName);
        System.out.println(pathName);
    }
}



